import * as bm from "/js/baseModule.js";
let Clipboard = require("/js/clipboard.js");
export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;
       
        that.feedData = {
            enable: true,
            info: "",
            free_reason_left_times: 0,		//无理由剩余次数
            free_reason_info: "",
            reason_left_times: 0,		//有理由剩余次数
            reason_info: "",
            feedback_contact_user: {		//联系人信息
                nickname: "",
                contact: "",
                type: ""
            },
            reason_options: []
        };
        let id = globalData.current_demand.id || funs.qs('did');
        api.feedbackTypes({ demand_id: id }, {
            succ: function (json) {
                $.extend(true, that.feedData, json);
            }
        });

        let dom = this.find('.FeedbackDemand_vue')[0];
        this.vue = new Vue({
            el: dom,
            data: {
                current_demand: globalData.current_demand,
                feedback_data: that.feedData,
            },
            computed: {
                oneDay: function () {
                    let startTime = globalData.current_demand.bid_win_at;
                    let stime = startTime * 1000;
                    let date = new Date().getTime();
                    let gapMin = Math.floor((date - stime) / 1000 / 60);
                    if (gapMin <= 0) {
                        //防止偶尔出现的js取时间不准确
                        gapMin = 1;
                    }

                    if (gapMin > (60 * 24)) {
                        return false;
                    }
                    return true;
                },
            }
        });

        /**
         * 如果是直接进入当前页面，则先loading一会儿，等数据回来
         */
        if (globalData.entryPage == 'project/FeedbackDemand') {
            let id = globalData.current_demand.id || funs.qs('did');
            api.getDemandInfo({ "id": id }, {
                succ: function (demand) {
                    $.extend(true, globalData.current_demand, demand);
                    that._init();
                    setTimeout(function () {
                        funs.removeWelcome();
                    }, 300);
                },
                fail: function (json) {
                    //  如果是项目已被删除或者不存在
                    if (json.name = "41004002") {
                        funs.openModal('modules/modals/CommonModal.JS', function (mod) {
                            mod.setType(9);
                        })
                    } else {
                        funs.tip(json.msg, '', 'fail');
                        setTimeout(function () {
                            that._evt_goback();
                        }, 2000)
                    }
                }
            })
        } else {
            that._init();
        }
        //监听数据返回
        $(document).on('data_update', function () {
            // 如果是直接进入当前页面，且项目已被删除或者不存在，则回到项目大厅
            if (globalData.currPage == 'feedbackdemand' && globalData.current_demand.uid == '0000X') {
                //订单不可见
                funs.openModal('modules/modals/CommonModal.JS', function (mod) {
                    mod.setType(9);
                })
            }
        });

         that.wxTip = that.find(".tip-copy");
        /*一键复制插件初始化实例*/
        var clipboard = new Clipboard('.wx-code').on('success', function (e) {
            var e = e || window.event;
            console.log(e);
            that.wxTip.show();
            setTimeout(function () {
                that.wxTip.hide();
            }, 2000);
        }).on('error', function (e) { });

    }

    _init() {
        /**
        * 取回基本信息
        */
        // let that = this;
        // let id = globalData.current_demand.id || funs.qs('did');
        // api.feedbackTypes({ demand_id: id }, {
        //     succ: function (json) {
        //         $.extend(true, that.feedData, json.body);
        //     }
        // });

        //feedback_status==2（审核中）或者feedback_status==3（成功）进入结果页
        // if (globalData.current_demand.feedback_info.feedback_status == 2 || globalData.current_demand.feedback_info.feedback_status == 3) {
        //     location.hash = 'project/FeedbackDemand/FeedbackResult';
        // }
    }

    /**查看该项目 */
    _evt_projectDetail() {
        let pro_info = globalData.current_demand;
        if (pro_info) {
            globalData.current_demand = pro_info;
            location.hash = 'demand?did=' + pro_info.id;
        }
    }
    _evt_FeedbackLock() {
        location.hash = 'project/FeedbackDemand/FeedbackLock';
    }
    getData() {
        return this.feedData;
    }
    _evt_FeedbackCancel() {
        var that = this;
        location.hash = 'project/FeedbackDemand/FeedbackCancel';
    }
}
